Skip to content

Modernize C# code snippets - System/Type - #12973

Draft
gewarren wants to merge 6 commits into
dotnet:mainfrom
gewarren:modernize-code-system-type
Draft

Modernize C# code snippets - System/Type#12973
gewarren wants to merge 6 commits into
dotnet:mainfrom
gewarren:modernize-code-system-type

Conversation

@gewarren

@gewarren gewarren commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Contributes to #12713.


Internal previews

Toggle expand/collapse
File Preview link
snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs Preview published page
snippets/csharp/System/Type/Attributes/attributes1.cs Preview published page
snippets/csharp/System/Type/BaseType/basetype3.cs Preview published page
snippets/csharp/System/Type/BaseType/remarks.cs Preview published page
snippets/csharp/System/Type/BaseType/testbasetype.cs Preview published page
snippets/csharp/System/Type/ContainsGenericParameters/source.cs Preview published page
snippets/csharp/System/Type/DeclaringMethod/source.cs Preview published page
snippets/csharp/System/Type/DeclaringType/remarks.cs Preview published page
snippets/csharp/System/Type/DeclaringType/source.cs Preview published page
snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs Preview published page
snippets/csharp/System/Type/EmptyTypes/source.cs Preview published page
snippets/csharp/System/Type/Equals/EqualsEx1.cs Preview published page
snippets/csharp/System/Type/Equals/source.cs Preview published page
snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs Preview published page
snippets/csharp/System/Type/FilterName/source.cs Preview published page
snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs Preview published page
snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs Preview published page
snippets/csharp/System/Type/FindMembers/type_findmembers.cs Preview published page
snippets/csharp/System/Type/FullName/Fullname3.cs Preview published page
snippets/csharp/System/Type/FullName/Fullname4.cs Preview published page
snippets/csharp/System/Type/FullName/Fullname5.cs Preview published page
snippets/csharp/System/Type/FullName/fullnameex1.cs Preview published page
snippets/csharp/System/Type/FullName/testfullname.cs Preview published page
snippets/csharp/System/Type/GenericParameterAttributes/source.cs Preview published page
snippets/csharp/System/Type/GenericParameterPosition/remarks.cs Preview published page
snippets/csharp/System/Type/GetArrayRank/type_getarrayrank.cs Preview published page
snippets/csharp/System/Type/GetConstructors/source1.cs Preview published page
snippets/csharp/System/Type/GetConstructors/source2.cs Preview published page
snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs Preview published page
snippets/csharp/System/Type/GetElementType/testgetelementtype.cs Preview published page

Note

This table shows the first 30 preview links (sorted alphabetically by file path) found in the OPS build report. For the full list, select OpenPublishing.Build Details within checks.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the C# code snippets under snippets/csharp/System/Type (and a few related System/Type*Exception and System/TypedReference snippets) as part of issue #12713, primarily by updating syntax/formatting to contemporary C# patterns while keeping the snippet intent the same.

Changes:

  • Replaced older formatting patterns (string.Format, composite formatting, explicit type names like String/Object) with modern C# ($"", target-typed new, string/object, expression-bodied members).
  • Cleaned up spacing/indentation and simplified small members (properties, constructors, helpers).
  • Removed some unused using directives and normalized using/header formatting.

Reviewed changes

Copilot reviewed 123 out of 130 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs Modernized string formatting and indentation in TypeLoadException example.
snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor3.cs Normalized formatting and minor syntax updates in P/Invoke TypeLoadException sample.
snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor2.cs Updated to interpolated strings and consistent formatting.
snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs Removed unused using static and updated to target-typed new.
snippets/csharp/System/TypeInitializationException/Overview/Missing1a.cs Converted trivial members to expression-bodied form.
snippets/csharp/System/TypeInitializationException/Overview/Missing1.cs Applied target-typed new, expression-bodied members, and whitespace cleanup in example/output comments.
snippets/csharp/System/TypeInitializationException/Overview/ctorException1.cs Applied target-typed new and whitespace cleanup in example/output comments.
snippets/csharp/System/TypedReference/Overview/source.cs Re-indented and normalized try/catch structure around snippet region.
snippets/csharp/System/Type/TypeHandle/type_typehandle.cs Removed unused using System.Reflection;, target-typed new, and interpolated strings.
snippets/csharp/System/Type/StructLayoutAttribute/source.cs Reformatted attribute usage/struct declaration and compacted helper to expression-bodied form.
snippets/csharp/System/Type/ReflectedType/source.cs Removed unused using System.Reflection; and updated to interpolated string.
snippets/csharp/System/Type/Overview/source.cs Updated typeof(string), object, and output formatting to interpolated strings.
snippets/csharp/System/Type/Overview/GetType1.cs Normalized file header and made foreach element type explicit.
snippets/csharp/System/Type/Overview/Equals1.cs Switched Object.ReferenceEquals to object.ReferenceEquals.
snippets/csharp/System/Type/Module/type_tostring.cs Updated output to interpolated strings and normalized snippet header/footer whitespace.
snippets/csharp/System/Type/Missing/source.cs Updated argument spacing and modernized CompilerParameters construction with object initializer.
snippets/csharp/System/Type/MakeGenericType/source.cs Removed unused using System.Reflection; and modernized output formatting and type keywords.
snippets/csharp/System/Type/MakeGenericType/remarks.cs Removed unused using System; and normalized brace spacing in nested type declarations.
snippets/csharp/System/Type/MakeByRefType/source.cs Updated output to interpolated strings and normalized catch spacing.
snippets/csharp/System/Type/IsVisible/source.cs Normalized whitespace and updated output formatting.
snippets/csharp/System/Type/IsValueType/type_isvaluetype.cs Normalized parameter spacing and updated output formatting.
snippets/csharp/System/Type/IsSubclassOf/testissubclassof.cs Converted Main to expression-bodied with interpolated output.
snippets/csharp/System/Type/IsSubclassOf/issubclassof_interface1.cs Modernized formatting and output strings for interface example.
snippets/csharp/System/Type/IsSealed/type_issealed.cs Normalized indentation and updated output to interpolated string.
snippets/csharp/System/Type/IsPublic/type_ispublic.cs Target-typed new and interpolated output.
snippets/csharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.cs Modernized formatting, target-typed new, and interpolated exception output.
snippets/csharp/System/Type/IsNotPublic/source.cs Removed unused using System.IO; and updated output to interpolated strings.
snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs Modernized formatting and updated per-property output to interpolated strings.
snippets/csharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.cs Modernized formatting, target-typed new, and interpolated exception output.
snippets/csharp/System/Type/IsLayoutSequential/type_islayoutsequential.cs Removed unused usings and updated output/instantiations to modern syntax.
snippets/csharp/System/Type/IsInterface/type_isinterface.cs Normalized formatting and updated output to interpolated strings.
snippets/csharp/System/Type/IsInstanceOfType/testisinstanceoftype.cs Normalized formatting/brace spacing and updated output to interpolated strings.
snippets/csharp/System/Type/IsGenericType/source.cs Removed unused using System.Reflection; and normalized generic type formatting/spacing.
snippets/csharp/System/Type/IsGenericType/remarks.cs Removed unused usings and normalized generic type formatting/spacing.
snippets/csharp/System/Type/IsGenericParameter/source.cs Removed unused using System.Reflection; and updated output/collection instantiation to modern syntax.
snippets/csharp/System/Type/IsExplicitLayout/type_isexplicitlayout.cs Removed unused usings, normalized attribute formatting, and updated output string.
snippets/csharp/System/Type/IsEnum/testisenum.cs Updated output to interpolated strings and normalized indentation.
snippets/csharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.cs Modernized formatting, target-typed new, and interpolated exception output.
snippets/csharp/System/Type/IsContextful/type_iscontextful.cs Removed unused remoting using and modernized output formatting and spacing.
snippets/csharp/System/Type/IsClass/type_isclass.cs Removed unused using System.Reflection; and modernized output formatting/spacing.
snippets/csharp/System/Type/IsAutoLayout/type_isautolayout.cs Normalized spacing and updated output to interpolated string.
snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs Modernized instantiation and updated output to interpolated strings.
snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs Normalized indentation and snippet-marker placement around if assignment.
snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs Normalized indentation and brace spacing.
snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs Updated AssemblyName construction to object initializer and normalized indentation.
snippets/csharp/System/Type/IsArrayImpl/type_isarrayimpl.cs Modernized ctor to expression-bodied, normalized spacing, and updated output/interpolation.
snippets/csharp/System/Type/IsArray/isarray2.cs Updated to typeof(string)/generic type keywords and modernized console output formatting.
snippets/csharp/System/Type/IsAnsiClass/type_isansiclass.cs Normalized spacing, target-typed new, and updated output strings.
snippets/csharp/System/Type/IsAbstract/isabstract1.cs Modernized formatting and updated output to interpolated strings.
snippets/csharp/System/Type/InvokeMember/invokemem.cs Updated primitive/type keywords, modernized arrays/boxing, and moved to interpolated strings.
snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs Modernized ctor to expression-bodied, normalized spacing, and updated output/interpolation.
snippets/csharp/System/Type/HasElementType/type_haselementtype.cs Converted trivial method to expression-bodied, normalized array formatting, and updated output to interpolated strings.
snippets/csharp/System/Type/GUID/type_guid.cs Normalized spacing and snippet header/footer, kept concatenation style in output.
snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs Normalized spacing, updated output to interpolation, and catch formatting.
snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs Normalized spacing, updated output to interpolation, and catch formatting.
snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs Normalized spacing, updated output to interpolation, and catch formatting.
snippets/csharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.cs Removed unused using System.Reflection;, target-typed new, and normalized snippet marker indentation.
snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs Normalized attribute spacing and updated output to interpolated strings; cleaned up comment wrapping.
snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs Removed unused using System.Runtime.InteropServices; and updated output to interpolation.
snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs Removed unused interop using and normalized try/catch formatting.
snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs Normalized formatting and indentation while keeping COMException catch.
snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs Removed unused interop using and normalized try/catch formatting.
snippets/csharp/System/Type/GetTypeCode/iconvertible.cs Simplified many members to expression-bodied form and modernized formatting/output.
snippets/csharp/System/Type/GetType/type_gettype.cs Updated to interpolated strings and normalized try/catch formatting.
snippets/csharp/System/Type/GetType/source.cs Normalized file header (BOM) formatting.
snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.cs Removed unused using System; and normalized brace spacing.
snippets/csharp/System/Type/GetProperty/type_getproperty3.cs Converted indexer accessors to expression-bodied and updated output to interpolated string.
snippets/csharp/System/Type/GetProperty/type_getproperty21.cs Normalized array type spacing and converted indexer accessors to expression-bodied.
snippets/csharp/System/Type/GetProperty/type_getproperty2.cs Updated output to interpolated string.
snippets/csharp/System/Type/GetProperty/type_getproperty1.cs Updated output to interpolated string.
snippets/csharp/System/Type/GetProperty/type_getproperty_types.cs Updated output/catch logging to interpolated strings and normalized snippet footer.
snippets/csharp/System/Type/GetProperties/type_gettypecode.cs Normalized snippet marker indentation, updated to interpolated strings, and cleaned up loops/catches.
snippets/csharp/System/Type/GetProperties/type_getproperties2.cs Converted trivial properties to expression-bodied and modernized formatting/output strings.
snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs Removed unused using System.Reflection; and updated output to interpolated strings.
snippets/csharp/System/Type/GetNestedTypes/type_getnestedclassesabs.cs Updated output to interpolated strings and normalized binding flags spacing.
snippets/csharp/System/Type/GetMethods/type_getmethods2.cs Removed unused using System.Reflection.Emit; and simplified methods/output formatting.
snippets/csharp/System/Type/GetMethod/type_getmethod5.cs Updated outputs to interpolated strings and converted out-parameter method to expression-bodied.
snippets/csharp/System/Type/GetMethod/type_getmethod4.cs Updated outputs to interpolated strings and converted out-parameter method to expression-bodied.
snippets/csharp/System/Type/GetMethod/type_getmethod3.cs Updated outputs to interpolated strings and converted out-parameter method to expression-bodied.
snippets/csharp/System/Type/GetMethod/type_getmethod2.cs Updated output to interpolated string.
snippets/csharp/System/Type/GetMethod/type_getmethod1.cs Updated output to interpolated string.
snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads2.cs Updated type keywords, normalized typeof(int), and modernized output formatting.
snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads1.cs Simplified methods to expression-bodied and modernized output formatting.
snippets/csharp/System/Type/GetMethod/GetMethod1.cs Modernized generic/non-generic Add method lookup sample and output formatting.
snippets/csharp/System/Type/GetMembers/type_getmembers2.cs Modernized instantiation, normalized formatting, and updated output to interpolated strings.
snippets/csharp/System/Type/GetMembers/type_getmembers1.cs Modernized instantiation, normalized formatting, and updated output to interpolated strings.
snippets/csharp/System/Type/GetMember/type_getmember.cs Modernized instantiation, type keywords, and output formatting/loop style.
snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs Modernized output formatting and normalized loop indentation.
snippets/csharp/System/Type/GetInterface/type_getinterface.cs Modernized instantiation/output formatting and snippet marker indentation (but currently has a compile error).
snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs Normalized whitespace and updated output to interpolated string in one case.
snippets/csharp/System/Type/GetGenericTypeDefinition/source.cs Removed unused using System.Reflection;, modernized dictionary creation, and updated output to interpolation.
snippets/csharp/System/Type/GetGenericArguments/source.cs Removed unused using System.Reflection;, modernized dictionary creation, and updated output to interpolation.
snippets/csharp/System/Type/GetFields/source.cs Normalized file header and converted trivial method body to expression-bodied form.
snippets/csharp/System/Type/GetFields/fieldinfo_isspecialname.cs Updated loop/catch spacing and output to interpolated string.
snippets/csharp/System/Type/GetField/type_getfield.cs Converted simple getter to expression-bodied and modernized output to interpolated strings.
snippets/csharp/System/Type/GetEvents/type_getevents2.cs Normalized catch spacing and snippet footer formatting.
snippets/csharp/System/Type/GetEvents/type_getevents1.cs Normalized catch spacing and snippet footer formatting.
snippets/csharp/System/Type/GetEvent/type_getevent1.cs Normalized if/catch spacing and updated one output to interpolated string.
snippets/csharp/System/Type/GetEvent/type_getevent.cs Normalized if/catch spacing and updated one output to interpolated string.
snippets/csharp/System/Type/GetElementType/testgetelementtype.cs Normalized array formatting, target-typed new, and updated output to interpolated strings.
snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs Simplified property to expression-bodied and normalized catch spacing.
snippets/csharp/System/Type/GetDefaultMembers/source2.cs Simplified accessors to expression-bodied and updated output to interpolated strings.
snippets/csharp/System/Type/GetConstructors/source2.cs Normalized indentation/brace style and spacing in constructor reflection sample.
snippets/csharp/System/Type/GetConstructors/source1.cs Normalized indentation/brace style and spacing in constructor reflection sample.
snippets/csharp/System/Type/GetArrayRank/type_getarrayrank.cs Normalized array formatting and updated dimension output to interpolation.
snippets/csharp/System/Type/GenericParameterPosition/remarks.cs Removed unused using System; and simplified generic method to expression-bodied.
snippets/csharp/System/Type/GenericParameterAttributes/source.cs Normalized generic type/constraint formatting and updated output to interpolation.
snippets/csharp/System/Type/FullName/testfullname.cs Fixed indentation and updated output to interpolated string.
snippets/csharp/System/Type/FullName/fullnameex1.cs Target-typed new and normalized indentation.
snippets/csharp/System/Type/FullName/Fullname5.cs Removed unused using System.Reflection; and updated output to interpolated strings.
snippets/csharp/System/Type/FullName/Fullname4.cs Modernized output formatting and simplified one method to expression-bodied.
snippets/csharp/System/Type/FullName/Fullname3.cs Removed unused using System.Reflection; and normalized indentation/loop formatting.
snippets/csharp/System/Type/FindMembers/type_findmembers.cs Modernized instantiation/type keywords and updated output formatting/spacing.
snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs Target-typed new, normalized spacing, and updated output to interpolated strings.
snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs Updated to typeof(string) and normalized spacing/exception catches.
snippets/csharp/System/Type/FilterName/source.cs Normalized indentation and snippet marker placement; formatted sample Application class.
snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs Updated to typeof(string) and normalized spacing/exception catches.
snippets/csharp/System/Type/Equals/source.cs Removed unused using System.Reflection;, updated type keywords, and modernized output formatting.
snippets/csharp/System/Type/Equals/EqualsEx1.cs Updated type keywords/instantiation and modernized output formatting.
snippets/csharp/System/Type/EmptyTypes/source.cs Removed unused using System.IO; and normalized brace style.
snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs Target-typed new, normalized array creation spacing, and simplified method to expression-bodied.
snippets/csharp/System/Type/DeclaringType/source.cs Removed unused using System.Reflection; and made Main expression-bodied with interpolated output.
snippets/csharp/System/Type/DeclaringType/remarks.cs Normalized snippet marker indentation and updated output to interpolated string.
snippets/csharp/System/Type/DeclaringMethod/source.cs Converted trivial method to expression-bodied, normalized output formatting, and array spacing.
snippets/csharp/System/Type/ContainsGenericParameters/source.cs Removed unused usings and updated outputs to interpolated strings.
snippets/csharp/System/Type/BaseType/testbasetype.cs Updated output to interpolated string.
snippets/csharp/System/Type/BaseType/remarks.cs Removed unused using System; and normalized empty Main formatting.
snippets/csharp/System/Type/BaseType/basetype3.cs Normalized indentation and updated output to interpolated strings.
snippets/csharp/System/Type/Attributes/attributes1.cs Normalized indentation/spacing and updated outputs to interpolated strings.
snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs Updated type keywords and normalized a few object/type instantiations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread snippets/csharp/System/Type/GetInterface/type_getinterface.cs Outdated
gewarren and others added 5 commits August 12, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants